#include <iostream>
#include <string>
#include <map>
#include <cmath>
using namespace std;

bool is_prime(int n)
{
    if (n <= 1)
        return false;
    
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
            return false;
    }
    
    return true;
}

int main()
{
    string s;
    string word = "";
    string number = "";

    map<string, string> digits = {
        {"one", "1"},
        {"two", "2"},
        {"three", "3"},
        {"four", "4"},
        {"five", "5"},
        {"six", "6"},
        {"seven", "7"},
        {"eight", "8"},
        {"nine", "9"},
    };

    getline(cin, s);

    int index = 0;
    while (index < (int)s.size())
    {
        while (s[index] == ' ')
        {
            index++;
        }

        word = "";
        while (index < (int)s.size() and s[index] != ' ')
        {
            word = word + s[index];
            index++;
        }

        if (digits.find(word) == digits.end())
        {
            cout << "Wrong input" << endl;
            return 0;
        }

        number = number + digits[word];
    }

    int n = stoi(number);

    if (s.size() != 13)
    {
        cout << "Wrong input" << endl;
        return 0;
    }

    int lower_prime = n;
    int upper_prime = n;

    while (!is_prime(lower_prime) || !is_prime(upper_prime))
    {
        lower_prime--;
        upper_prime++;
    }

    while (!is_prime(lower_prime))
    {
        lower_prime--;
    }
    while (!is_prime(upper_prime))
    {
        upper_prime++;
    }

    if (n - lower_prime <= upper_prime - n)
    {
        cout << lower_prime;
    }
    else
    {
        cout << upper_prime;
    }

    return 0;
}